package com.zsj.entity;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.zsj.enums.ErrorCodeEnum;
import lombok.Data;

/**
 * @Description:
 * @Author:
 * @Date:
 */
@Data
public class WebResponse<T> {

    @JsonProperty("Code")
    private String code;

    @JsonProperty("Msg")
    private String message;

    @JsonProperty("Data")
    private T data;

    private WebResponse(String code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    private WebResponse(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public static <T> WebResponse<T> success() {
        return new WebResponse<>(ErrorCodeEnum.SUCCESS.getCode(), ErrorCodeEnum.SUCCESS.getMsg());
    }

    public static <T> WebResponse<T> success(T data) {
        return new WebResponse<>(ErrorCodeEnum.SUCCESS.getCode(), ErrorCodeEnum.SUCCESS.getMsg(), data);
    }

    public static <T> WebResponse<T> fail(ErrorCodeEnum errorCodeEnum) {
        return new WebResponse<>(errorCodeEnum.getCode(), errorCodeEnum.getMsg());
    }
}
